<template>
	<view>
		<div style="background-color: blue; width: 100%; height: 100rpx; " @touchstart="touchStart" @touchend="touchEnd"></div>
		在上面蓝色区域进行左右滑动
	</view>
</template>

<script>
export default {
	data() {
		return {
			startX: 0 // 点击位置的x坐标，用来判断滑动事件
		};
	},
	methods: {
		// 滑动事件,移除购物车商品
		touchStart(event) {
			this.curCartGoodsIndex = event.currentTarget.dataset.index;
			if (event.touches.length == 1) this.startX = event.touches[0].clientX;
		},
		touchEnd(event) {
			let that = this;
			if (event.changedTouches.length == 1) {
				let endX = event.changedTouches[0].clientX;
				let diff = endX - this.startX;
				if (diff > 70) {
					this.$msg('右滑动事件');
				} else if (diff < -70) {
					this.$msg('左滑动事件');
				}
			}
		}
	}
};
</script>

<style></style>
